// bosstwin.txt

// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//   Cell 3 - Who is this char's twin?

begincreaturescript;

variables;

short i,target;
short heal_level = 300;
short last_heal;
short last_abil;
short which_ae = 0;
body;

beginstate INIT_STATE;
	set_name(ME,"Pairbond Construct");
	set_level(ME,35);
	change_max_health(ME,300);
	set_boss_level(ME,2);
	set_attack_bonus(ME,10);
	last_heal = get_current_tick();
	last_abil = get_current_tick();
	
	break;

beginstate DEAD_STATE;
	if ((get_memory_cell(1) != 0) || (get_memory_cell(2) != 0))
		inc_flag(get_memory_cell(1),get_memory_cell(2),1);
break;

beginstate START_STATE; 
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	if ((get_attitude(ME) >= 10) && (gf(80,7) > 0)) {
		set_foe_target(ME,pc_num());
		set_state(3);
		}

	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if ((char_ok(get_memory_cell(3))) && (can_see_char(get_memory_cell(3)))) {
		if ((tick_difference(last_heal,get_current_tick()) > 0) && (get_health(ME) < get_max_health(ME) - 100)) {
			last_heal = get_current_tick();
			print_named_str(ME,"sees its twin nearby. The shade draws energy from it.");
			heal_char(ME,heal_level);
			heal_level = heal_level + 300;
			pc_heard_sound_delay(100,300);						
			run_sparkles_on_char(ME,6,8,1);
			}
		}
	if ((char_ok(get_memory_cell(3)) == FALSE) || (can_see_char(get_memory_cell(3)) == FALSE)) 
		heal_level = 300;
		
	if (target_ok() == FALSE)
		set_state(START_STATE);

	if ((my_number() == 37) && (is_combat()) && 
	  (tick_difference(last_abil,get_current_tick()) > 0)) {
		run_char_animation(2,1,35);	
		last_abil = get_current_tick();
	  	if (which_ae == 0) { // fire
		  	which_ae = 1;
		  	place_particle_num(ME,2,4,8);
			print_named_str(ME,"surrounds itself with a curtain of flame.");
			pc_heard_sound_delay(117,250);						
	  		create_missile_spiral(154,40,8,2);
	  		damage_nearby(get_ran(1,500,700),8,2,0);
	  		}
	  		else {
		  		which_ae = 0;
			  	place_particle_num(ME,4,6,8);
				print_named_str(ME,"emits an aura of terror.");
				pc_heard_sound_delay(107,250);						
				status_nearby(75,8,7,0);
	  			}
			end();
		}  	
		
	if ((my_number() == 36) && (is_combat()) && 
	  (tick_difference(last_abil,get_current_tick()) > 0)) {
		run_char_animation(2,1,35);	
		last_abil = get_current_tick();
	  	if (which_ae == 0) { // fire
		  	which_ae = 1;
		  	place_particle_num(ME,4,6,8);
			print_named_str(ME,"emits an acid spray.");
			pc_heard_sound_delay(177,250);			
	  		create_missile_spiral(142,40,8,2);
			status_nearby(get_level(ME) + 5 + get_attack_bonus(ME),8,6,0);
	  		damage_nearby(get_ran(1,400,500),8,5,0);
	  		}
	  		else {
		  		which_ae = 0;
		 	 	place_particle_num(ME,3,6,8);
				print_named_str(ME,"cast a slowing spell.");
				pc_heard_sound_delay(136,250);						
				status_nearby(-6,8,1,0);
	  			}
			end();
		}  			

	do_attack();
break;

beginstate TALKING_STATE;
	print_str("Talking: It doesn't respond.");
break;